package core

// PageSupport 数据库分页对象
type PageSupport[T any] struct {
	Keyword    string `json:"keyword" form:"keyword"`
	PageNo     int    `json:"pageNo" form:"pageNo"`
	PageSize   int    `json:"pageSize" form:"pageSize"`
	PageCount  int    `json:"pageCount"`
	TotalCount int64  `json:"totalCount"`
	Data       []T    `json:"data"`
}

func (ps *PageSupport[T]) SetData(data []T) {
	ps.Data = data
}

func (ps *PageSupport[T]) GetOffSet() int {
	if ps.PageNo == 0 {
		return 0
	} else if ps.PageNo == 1 {
		return 0
	} else {
		return (ps.PageNo - 1) * ps.GetPageSize()
	}
}

func (ps *PageSupport[T]) GetPageSize() int {
	if ps.PageSize <= 0 {
		return 10
	} else {
		return ps.PageSize
	}
}
